var PATH_PREFIX ="";

function setPathPrefix(path){
	PATH_PREFIX =  path;
}
$(function() {
	// 给select2组件加载样式
	WASP_WIDGET.initializeSelectStyle();
	// 注册清空事件
    WASP_WIDGET.registerResetClearEvent();
    
    WASP_WIDGET.triggerDateStyleWithYMD($("#beginDate"));
    WASP_WIDGET.triggerDateStyleWithYMD($("#endDate"));
    //初始化产品下拉框
    WASP_WIDGET.triggerPrdInfoSelect("prjCode");
});

var $investReportList = $('#investReportList');

$(function() {
	$investReportList.jqGrid({   
		url:PATH_PREFIX+'investReportListPage.do',    
		//caption:'投资报告列表<button type="button" class="btn btn-default btn-sm btn-small btn-fullscreen" title="" tabindex="-1"><i class="fa fa-arrows-alt icon-fullscreen"></i></button>',  
		datatype: "json",
		colNames:["主键","产品名称","资产单元","交易单元","订单日期","成交日期","成交金额","交易费用","备注"],        
		colModel:[  { name: 'reportId', index: 'reportId', hidden: true, key: true, resizable: true, sortable: false },       
		            { name: 'productId', index: 'productId', resizable: true, sortable: false },
		            { name: 'asseUnitName', index: 'asseUnitName', resizable: true, sortable: false },
		            { name: 'tradeUnitName', index: 'tradeUnitName', resizable: true, sortable: false },
		            { name: 'orderDate', index: 'orderDate', resizable: true, sortable: false },
		            { name: 'dealDate', index: 'dealDate', resizable: true, sortable: false },
		            { name: 'dealPrice', index: 'dealPrice', resizable: true, sortable: false },
		            { name: 'investPrice', index: 'investPrice', resizable: true, sortable: false },
		            { name: 'remarks', index: 'remarks', resizable: true, sortable: false }
				  ],
		rowNum: 10,
        rowList: [10, 20, 30, 50],
        rownumbers: true,
        rownumWidth: 50,
        prmNames: { search: "search", page: "pageNo", rows: "limit" },
        height: '340',
        width: false,
        autowidth:true,
        editurl: '',
        viewrecords: true,
        cellEdit: false,
        shrinkToFit: true,
        grouping: false,
        jsonReader: {
            root: "items", //结果集
            records: "total", //总记录数 
            total: "pageCount", //总页数
            page: "pageNo", //当前页 
            repeatitems: false // (4) 
        },  
		multiselect:false,
		pager: "#investReportListPage",						
		gridComplete: function(){
			
		}
	});
	$investReportList.navGrid('#investReportListage',{edit:false,add:false,del:false,search:false,refreshstate:'current'});
	$investReportList.jqGrid('setFrozenColumns');
	jqGridResize($investReportList);
	$(".ui-jqgrid .ui-jqgrid-htable").css("width",$(".ui-jqgrid").width()-1);
	$(".ui-jqgrid .ui-jqgrid-btable").css("width",$(".ui-jqgrid").width()-1);
});

/**
 * 查询按钮
 * 根据条件查询数据
 * @param flag
 */
function queryByCondtion(flag){
    var postData = $investReportList.jqGrid("getGridParam", "postData");
    $.extend(postData, {
		'sp[securName]' : $("#securName").val(),
		'sp[securType]' : $("#securType").val()
	});
    if (flag) {
    	$investReportList.jqGrid("setGridParam",{"datatype": "json"}).trigger("reloadGrid",[{page:1}]);//重新载入Grid表格
    } else {
    	$investReportList.jqGrid("setGridParam",{"datatype": "json"}).trigger("reloadGrid");//重新载入Grid表格
    }
}

/**
 * 跳转投资标的新增页面
 * @returns
 */
function invesSecurAddView(){
	/** 新建 */
	 var url = PATH_PREFIX+"investTradeAddView.do";
	 openDialogCenter(url,550,950);
}


// 基于准备好的dom，初始化echarts实例
var myChart = echarts.init(document.getElementById('main'));

// 指定图表的配置项和数据
option = {
	    title : {
	        text: '区间持仓变动'
	    },
	    tooltip : {
	        trigger: 'axis'
	    },
	    legend: {
	        data:['财富管家','利多多','月月盈']
	    },
	    toolbox: {
	        show : false,
	        feature : {
	            mark : {show: true},
	            dataView : {show: true, readOnly: false},
	            magicType : {show: true, type: ['line', 'bar']},
	            restore : {show: true},
	            saveAsImage : {show: true}
	        }
	    },
	    calculable : true,
	    xAxis : [
	        {
	            type : 'category',
	            boundaryGap : false,
	            data : ['','','','','','','','','']
	        }
	    ],
	    yAxis : [
	        {
	            type : 'value',
	            axisLabel : {
	            }
	        }
	    ],
	    series : [
	        {
	            name:'财富管家',
	            type:'line',
	            data:[2,3.4,4.8,4.6,4.4,4.2,4.0,5.5,7],
	        },
	        {
	            name:'利多多',
	            type:'line',
	            data:[3.6,3.7,3.8,4.5,5.3,4.4,3.5,3.7,3.9],
	        },
	        {
	            name:'月月盈',
	            type:'line',
	            data:[,,1,1.5,2.0,2.1,2.2,2.6,3.0],
	        }
	    ]
	};

// 使用刚指定的配置项和数据显示图表。
myChart.setOption(option);



//基于准备好的dom，初始化echarts实例
var myChart2 = echarts.init(document.getElementById('main2'));

// 指定图表的配置项和数据
option = {
	    title : {
	        text: '区间持仓占比',
	        x:'center'
	    },
	    tooltip : {
	        trigger: 'item',
	        formatter: "{b} : {d}%"
	    },
	    legend: {
	        orient : 'vertical',
	        x : 'left',
	        data:['','','','','']
	    },
	    toolbox: {
	        show : false,
	        feature : {
	            mark : {show: true},
	            dataView : {show: true, readOnly: false},
	            magicType : {
	                show: true, 
	                type: ['pie', 'funnel'],
	                option: {
	                    funnel: {
	                        x: '25%',
	                        width: '50%',
	                        funnelAlign: 'left',
	                        max: 1548
	                    }
	                }
	            },
	            restore : {show: true},
	            saveAsImage : {show: true}
	        }
	    },
	    calculable : true,
	    series : [
	        {
	            name:'',
	            type:'pie',
	            radius : '70%',
	            center: ['50%', '50%'],
	            data:[
	                {value:1250, name:'财富管家'},
	                {value:350, name:'利多多'},
	                {value:1500, name:'月月盈'},
	                {value:1900, name:'添富宝'}
	            ],
	            itemStyle:{
	            	normal:{
		            	label:{
			            	show: true,
			            	formatter: '{b} : {d}%'
		            	}
	            	}
	            }
	        }
	    ]
	};
// 使用刚指定的配置项和数据显示图表。
myChart2.setOption(option);
